package fr.ups.jim.isi.tp4;

import java.awt.Color;
import java.awt.Point;
import java.awt.geom.GeneralPath;
import java.awt.geom.AffineTransform;


public class PathItem extends CanvasItem {

	Point startPoint;
	
	PathItem (PersistentCanvas canvas, Color o, Color f, Point p) {
		super(canvas, o, f);
		GeneralPath path = new GeneralPath();
		path.moveTo(p.x, p.y);
		shape = path;
	}
	
	PathItem (PathItem originItem) {
		super(originItem.canvas, originItem.outlineColor, originItem.fillColor);
		shape = new GeneralPath(originItem.shape);
	}
	
	public CanvasItem duplicate() {
		PathItem newPath= new PathItem(this);
		newPath.move(10, 10);
		canvas.addItem(newPath);
		return newPath;
	}
	
	public void update(Point p) {
		((GeneralPath)shape).lineTo(p.x, p.y);
		canvas.repaint();
//		startPoint = new Point((GeneralPath)shape.getBounds().x, 
//				(GeneralPath)shape.getBounds().y);
	}

	public void move(int disX, int disY) {
		shape = AffineTransform.getTranslateInstance(disX, disY).createTransformedShape(shape);
		
		canvas.repaint();
	}
	
	

}
